import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class PropertiesUtils {
    private static final String PROPERTIES_FILE = "exam.properties";
    private static Properties properties = null;

    static {
        properties = new Properties();
        try {
            properties.load(new InputStreamReader(PropertiesUtils.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE),"utf-8"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getProperties(String key){
        String value = null;
        value = properties.getProperty(key);
        if (value == null || value.equals("")){
            throw new NoPropertiesException("配置文件中找不到对应属性");
        }
        return value;
    }
}
